﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TRPOP.CMS.RegAssembly;
using System.Text.RegularExpressions;
using TRPOP.Common;
using System.Collections;
using System.Data;
using TRPOP.CMS.Plugin;
using TRPOP.ComSqlDAL;
/*
 * 
 *   基本信息的处理
 * 
 */
namespace TRPOP.CMS.Template.GenerateCS
{
    /// <summary>
    /// 为cms标签 获取数据
    /// </summary>
    public class CMSTagGetData
    {
        public static IDAL m_IDAL = ITemplateAccess.GetIDalInstance();
        /// <summary>
        /// 获取结点信息
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataRow GetNodeInfo(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            Dictionary<string, string> oDicParam = new Dictionary<string, string>();

            #region 关于 nodeid 或 nodeguid 的逻辑处理
            if (oDictionary.ContainsKey("nodeguid") == false &&
                oDictionary.ContainsKey("nodeid") == false)
            {
                oDicParam.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
            }
            else if (oDictionary.ContainsKey("nodeguid"))
            {
                if (oDictionary["nodeguid"].IsEmpty())
                    oDicParam.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
                else
                    oDicParam.Add("nodeguid", oDictionary["nodeguid"]);
            }
            else
            {
                string strNodeid = oDictionary["nodeid"];
                if (strNodeid == "" || strNodeid == "self")//自动获取结点ID 
                    oDicParam.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
                else if (strNodeid == "parent")
                    oDicParam.Add("nodeid", oTemplatePageInfo.intCurrentNodeParentID.ToString());
                else
                    oDicParam.Add("nodeid", strNodeid);
            }

            #endregion

            #region returnkey处理 returnkey
            if (oDictionary.ContainsKey("returnkey"))
            {
                oDicParam.Add("returnkey", oDictionary["returnkey"]);
            }
            #endregion

            bool blnNodeguid = oDicParam.ContainsKey("nodeguid");
            string strNodeguid = blnNodeguid ? oDicParam["nodeguid"].ToString() : oDicParam["nodeid"];
            string strReturnkey = oDicParam.ContainsKey("returnkey") ? oDicParam["returnkey"].ToString() : "";

            return m_IDAL.GetNodeInfo(blnNodeguid, strNodeguid, false, strReturnkey);

        }

        /// <summary>
        /// 获取结点信息列表
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetNodeInfoList(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();

            Dictionary<string, string> oDicDataTableParam = new Dictionary<string, string>();

            #region 关于Type的逻辑处理 如果没有设置则直接结束
            if (oDictionary.ContainsKey("type") && oDictionary["type"].IsEmpty() == false)
            {
                oDicDataTableParam.Add("type", oDictionary["type"]);
            }
            else
                return oTableReturn;
            #endregion

            #region 关于 nodeid 或 nodeguid 的逻辑处理

            if (oDictionary.ContainsKey("nodeguid") && oDictionary["nodeguid"].IsEmpty() == false)
            {
                oDicDataTableParam.Add("nodeguid", oDictionary["nodeguid"]);
            }
            else if (oDictionary.ContainsKey("nodeid") == false)
                return oTableReturn;
            else
            {
                string strNodeid = oDictionary["nodeid"];
                if (strNodeid == "")//自动获取结点ID 
                    oDicDataTableParam.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
                else
                    oDicDataTableParam.Add("nodeid", strNodeid);
            }

            #endregion

            #region orderby处理 orderby
            if (oDictionary.ContainsKey("orderby") && oDictionary["orderby"].IsEmpty() == false)
            {
                oDicDataTableParam.Add("orderby", oDictionary["orderby"]);
            }
            #endregion

            #region Ignore处理 Ignore
            if (oDictionary.ContainsKey("ignore") && oDictionary["ignore"].IsEmpty() == false)
            {
                oDicDataTableParam.Add("ignore", oDictionary["ignore"]);
            }
            #endregion

            #region returnkey处理 returnkey
            if (oDictionary.ContainsKey("returnkey"))
            {
                oDicDataTableParam.Add("returnkey", oDictionary["returnkey"]);
            }
            #endregion

            #region 寻找数据

            string strType = oDicDataTableParam["type"];
            bool blnNodeguid = oDicDataTableParam.ContainsKey("nodeguid");
            string strNodeguid = oDicDataTableParam.ContainsKey("nodeguid") ? oDicDataTableParam["nodeguid"].ToString() : oDicDataTableParam["nodeid"].ToString();
            string strOrderby = oDicDataTableParam.ContainsKey("orderby") ? oDicDataTableParam["orderby"].ToString() : "";
            string strIgnore = oDicDataTableParam.ContainsKey("ignore") ? oDicDataTableParam["ignore"].ToString() : "";
            string strReturnkey = oDicDataTableParam.ContainsKey("returnkey") ? oDicDataTableParam["returnkey"].ToString() : "";

            switch (strType)
            {
                case "sub"://NodeID下的子结点
                    oTableReturn = m_IDAL.GetNodeListBySub(blnNodeguid, strNodeguid, strOrderby, strIgnore, false, strReturnkey);
                    break;
                case "set"://自定义的结点
                    oTableReturn = m_IDAL.GetNodeListBySet(blnNodeguid, strNodeguid, strOrderby, strIgnore, false, strReturnkey);
                    break;
                case "parent"://所有父级结点列表
                    oTableReturn = m_IDAL.GetNodeListByParent(blnNodeguid, strNodeguid, strOrderby, strIgnore, false, strReturnkey);
                    break;
                case "brother"://所有同级(兄)结点列表
                    oTableReturn = m_IDAL.GetNodeListByBrother(blnNodeguid, strNodeguid, strOrderby, strIgnore, false, strReturnkey);
                    break;
                case "son"://所有子结点列表，等同于“sub”
                    oTableReturn = m_IDAL.GetNodeListBySon(blnNodeguid, strNodeguid, strOrderby, strIgnore, false, strReturnkey);
                    break;
                default:
                    break;
            }

            #endregion

            return oTableReturn;
        }

        /// <summary>
        /// 获取内容信息
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetContentInfo(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            string strIndexids = oDictionary.ContainsKey("indexid") ? oDictionary["indexid"] : "";
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";
            return m_IDAL.GetContent(strIndexids, false, true, strReturnkey) as DataTable;
        }

        /// <summary>
        /// 获取附加发布信息
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetExtraPublish(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            //如果没有设定 nodeid，则将当前的nodeid设置为该nodeid
            string strNodeId = string.Empty;
            if (oDictionary.ContainsKey("nodeid") && !oDictionary["nodeid"].IsEmpty())
            {
                strNodeId = oDictionary["nodeid"];
            }
            else
                strNodeId = oTemplatePageInfo.intCurrentNodeID.ToString();

            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";
            return m_IDAL.GetExtraPublish(strNodeId, false, strReturnkey);
        }

        /// <summary>
        ///  统计标签的数据提取
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static string GetCount(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            //既不包含 function 也不包含 query 的话，则语法有问题，直接返回空
            if ((!oDictionary.ContainsKey("function") || oDictionary["function"].IsEmpty()) && (!oDictionary.ContainsKey("query") || oDictionary["query"].IsEmpty()))
                return string.Empty;

            string strFunction = oDictionary.ContainsKey("function") ? oDictionary["function"].ToString() : "";
            string strNodeid = oDictionary.ContainsKey("nodeid") ? oDictionary["nodeid"].ToString() : "";
            string strTableid = oDictionary.ContainsKey("tableid") ? oDictionary["tableid"].ToString() : "";
            string strWhere = oDictionary.ContainsKey("where") ? oDictionary["where"].ToString() : "";
            string strQuery = oDictionary.ContainsKey("query") ? oDictionary["query"].ToString() : "";
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";
            return m_IDAL.GetCount(strFunction, strNodeid, strTableid, strWhere, strQuery, false, strReturnkey);

        }

        /// <summary>
        /// 为sql标签获取数据
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetSqlData(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();
            // 暂不支持分页
            //if (oDictionary.ContainsKey("num"))
            //{
            //    CheckifPage(oDictionary, oTemplatePageInfo);
            //}
            string strQuery = oDictionary["query"];
            string strNum = oDictionary.ContainsKey("num") ? oDictionary["num"].ToString() : "";
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";

            //ListPagePutRealCountForSQL(strQuery, false, strReturnkey, oTemplatePageInfo);

            oTableReturn = m_IDAL.GetDatabySQLQuery(strQuery, strNum, false, strReturnkey);

            return oTableReturn;
        }

        /// <summary>
        /// 搜索标签的数据提取
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetSearchData(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();

            #region 关于nodeid的逻辑处理  NodeID   TableID

            //====只设置了 tableid  key: nodeguid 这里直接提取
            if (oDictionary.ContainsKey("nodeid") == false || oDictionary["nodeid"].IsEmpty())
            {
                if (oDictionary.ContainsKey("tableid") == false || oDictionary["tableid"].IsEmpty())
                    return oTableReturn;
            }
            else if (oDictionary.ContainsKey("nodeid"))
            {
                string strnodeid = oDictionary["nodeid"];
                if (strnodeid.IndexOf("all-") >= 0)   //NodeID="all-10" ：调用结点id为10(含所有子结点)下的内容 【并进行解析】
                {
                    oDictionary.Add("allsubnode", "true");
                    oDictionary["nodeid"] = strnodeid.Replace("all-", "");
                }
            }
            #endregion

            #region 调用条数处理 Num
            if (oDictionary.ContainsKey("num"))
            {
                CheckifPage(oDictionary, oTemplatePageInfo);
            }
            else
                return oTableReturn;
            #endregion

            if (!oDictionary.ContainsKey("keywords"))
            {
                return oTableReturn;
            }

            #region 寻找数据

            bool isPager = false;
            string strNum = oDictionary.ContainsKey("num") ? oDictionary["num"].ToString() : "";
            string strField = oDictionary.ContainsKey("field") ? oDictionary["field"].ToString() : "[Name],[SEOTitle]";
            string strKeywords = oDictionary.ContainsKey("keywords") ? oDictionary["keywords"].ToString() : "";
            string strSeparator = oDictionary.ContainsKey("separator") ? oDictionary["separator"].ToString() : ",";
            string strIgnorecontentid = oDictionary.ContainsKey("ignorecontentid") ? oDictionary["ignorecontentid"].ToString() : "";
            string strWhere = oDictionary.ContainsKey("where") ? oDictionary["where"].ToString() : "";
            string strOrderby = oDictionary.ContainsKey("orderby") ? oDictionary["orderby"].ToString() : "";
            bool blnExact = oDictionary.ContainsKey("exact") ? (oDictionary["orderby"].ToString() == "1") : false;
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";

            ListPagePutRealCountForSearch(oDictionary, strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, blnExact, oTemplatePageInfo);

            if (CheckTemplateTypeForList(oTemplatePageInfo) && oTemplatePageInfo.IsFindPager && oTemplatePageInfo.IsPagerOpered == false)
            {
                strWhere = strWhere + (strWhere.IsEmpty() ? "" : " and ") + oTemplatePageInfo.strPageWhereSql;
                oTemplatePageInfo.IsPagerOpered = true;
                isPager = true;
            }

            if (oDictionary.ContainsKey("nodeid"))
            {
                if (oDictionary.ContainsKey("allsubnode") && oDictionary["allsubnode"] == "true")
                {
                    oTableReturn = m_IDAL.GetSearchWithAllSonByNodeid(oDictionary["nodeid"], strNum, strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, strOrderby, blnExact, false, strReturnkey);
                }
                else
                {
                    oTableReturn = m_IDAL.GetSearchByNodeid(oDictionary["nodeid"], strNum, strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, strOrderby, blnExact, false, strReturnkey);
                }
            }
            else if (oDictionary.ContainsKey("tableid"))
            {
                oTableReturn = m_IDAL.GetSearchByTableid(oDictionary["tableid"], strNum, strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, strOrderby, blnExact, false, strReturnkey);
            }

            if (oTableReturn == null)
                oTableReturn = new DataTable();

            if (isPager && oTableReturn.Rows.Count <= 0)
            {
                oTemplatePageInfo.IsCurrentPageDataError = true;
            }

            #endregion

            return oTableReturn;
        }

        /// <summary>
        /// 为评论标签获取数据
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetCommentData(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();

            if (!oDictionary.ContainsKey("indexid"))
            {
                return oTableReturn;
            }

            #region 调用条数处理 Num
            if (oDictionary.ContainsKey("num"))
            {
                CheckifPage(oDictionary, oTemplatePageInfo);
            }
            else
                return oTableReturn;
            #endregion

            #region 寻找数据

            bool isPager = false;
            string strIndexid = oDictionary["indexid"];
            string strStart = oDictionary.ContainsKey("start") ? oDictionary["start"].ToString() : "";
            string strNum = oDictionary.ContainsKey("num") ? oDictionary["num"].ToString() : "";
            bool blnHiddenIp = (oDictionary.ContainsKey("hiddenip") && oDictionary["hiddenip"] == "1");
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";
            string strWhere = oDictionary.ContainsKey("where") ? oDictionary["where"].ToString() : "";

            RecPagePutRealCount(oDictionary, strWhere, oTemplatePageInfo);

            if (CheckTemplateTypeForList(oTemplatePageInfo) && oTemplatePageInfo.IsFindPager && oTemplatePageInfo.IsPagerOpered == false)
            {
                strWhere = strWhere + (strWhere.IsEmpty() ? "" : " and ") + oTemplatePageInfo.strPageWhereSql;
                oTemplatePageInfo.IsPagerOpered = true;
                isPager = true;
            }

            oTableReturn = m_IDAL.GetCommentList(strIndexid, strStart, strNum, blnHiddenIp, false, strReturnkey, strWhere);

            if (oTableReturn == null)
                oTableReturn = new DataTable();

            if (isPager && oTableReturn.Rows.Count <= 0)
            {
                oTemplatePageInfo.IsCurrentPageDataError = true;
            }

            #endregion

            return oTableReturn;
        }

        /// <summary>
        /// PAGESEARCH 标签
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetPageSearchData(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();

            #region 调用条数处理 Num
            if (oDictionary.ContainsKey("num"))
            {
                CheckifPage(oDictionary, oTemplatePageInfo);
            }
            else
                return oTableReturn;
            #endregion

            #region 寻找数据
            bool isPager = false;
            string strNum = oDictionary.ContainsKey("num") ? oDictionary["num"].ToString() : "";
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";
            
            int intCount = 0;
            if (oTemplatePageInfo.strAdvancedSearchCondation.IsEmpty())
            {
                oTableReturn = m_IDAL.GetPageSearchList(oTemplatePageInfo.intCurrentNodeID, oTemplatePageInfo.intListPagePubIndex, oTemplatePageInfo.intPageSize, oTemplatePageInfo.strSearchPageKeys, strReturnkey, out intCount);
            }
            else
            {
                oTableReturn = m_IDAL.GetPageAdvancedSearchList(oTemplatePageInfo.intCurrentNodeID, oTemplatePageInfo.intListPagePubIndex, oTemplatePageInfo.intPageSize, oTemplatePageInfo.strAdvancedSearchCondation, strReturnkey, out intCount);
            }
            if(oTemplatePageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.SearchPage && oTemplatePageInfo.IsFindPager && oTemplatePageInfo.IsPagerOpered == false)
            {
                oTemplatePageInfo.intPageRealCount = intCount;
                oTemplatePageInfo.IsPagerOpered = true;
                isPager = true;
            }

            if (oTableReturn == null)
                oTableReturn = new DataTable();

            if (isPager && oTableReturn.Rows.Count <= 0)
            {
                oTemplatePageInfo.IsCurrentPageDataError = true;
            }
            #endregion

            return oTableReturn;
        }

        /// <summary>
        /// 为list类型的cms标签获取数据
        /// </summary>
        /// <param name="oDictionary"></param>
        /// <param name="oTemplatePageInfo"></param>
        /// <returns></returns>
        public static DataTable GetListData(Dictionary<string, string> oDictionary, TemplateDllPageInfo oTemplatePageInfo)
        {
            DataTable oTableReturn = new DataTable();

            #region 关于node的逻辑处理  NodeID  NodeGUID  TableID
            string strNodeid = string.Empty;
            if (oDictionary.ContainsKey("nodeid") == false &&
                oDictionary.ContainsKey("tableid") == false &&
                oDictionary.ContainsKey("nodeguid") == false)
            {
                oDictionary.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
            }
            //====只设置了 NodeGUID  key: nodeguid 这里直接提取
            else if (oDictionary.ContainsKey("nodeguid") && oDictionary["nodeguid"].IsEmpty() && !oDictionary.ContainsKey("nodeid"))
            {
                oDictionary.Remove("nodeguid");
                oDictionary.Add("nodeid", oTemplatePageInfo.intCurrentNodeID.ToString());
            }
            else if (!oDictionary.ContainsKey("tableid"))
            {
                if (oDictionary["nodeid"].IsEmpty())
                {
                    oDictionary["nodeid"] = oTemplatePageInfo.intCurrentNodeID.ToString();
                }//====只根据 nodeid
                else
                {
                    string strnodeid = oDictionary["nodeid"];
                    if (strnodeid == "self")//NodeID="self"：自动获取结点ID 
                    {
                        oDictionary["nodeid"] = oTemplatePageInfo.intCurrentNodeID.ToString();
                    }
                    else if (strnodeid.Contains(","))//NodeID="1,2,3,4"：调用结点id分别为1,2,3,4下的内容 
                    {
                        ;
                    }
                    else if (strnodeid.IndexOf("all-") >= 0)//NodeID="all-10" ：调用结点id为10(含所有子结点)下的内容 【并进行解析】
                    {
                        oDictionary.Add("allsubnode", "true");
                        oDictionary["nodeid"] = strnodeid.Replace("all-", "");
                    }//NodeID="345"：调用单一结点id为345下的内容
                }
            }
            #endregion

            #region 调用条数处理 Num
            if (oDictionary.ContainsKey("num"))
            {
                CheckifPage(oDictionary, oTemplatePageInfo);
            }
            #endregion

            #region 寻找数据
            bool isPager = false;
            string strNum = oDictionary.ContainsKey("num") ? oDictionary["num"].ToString() : "";
            string strOrderby = oDictionary.ContainsKey("orderby") ? oDictionary["orderby"].ToString() : "";
            string strWhere = oDictionary.ContainsKey("where") ? oDictionary["where"].ToString() : "";
            string strIgnore = oDictionary.ContainsKey("ignore") ? oDictionary["ignore"].ToString() : "";
            string strReturnkey = oDictionary.ContainsKey("returnkey") ? oDictionary["returnkey"].ToString() : "";

            ListPagePutRealCount(oDictionary, strWhere, strIgnore, oTemplatePageInfo);

            if (CheckTemplateTypeForList(oTemplatePageInfo) &&
                oTemplatePageInfo.IsFindPager &&
                oTemplatePageInfo.IsPagerOpered == false)
            {
                strWhere = strWhere + (strWhere.IsEmpty() ? "" : " and ") + oTemplatePageInfo.strPageWhereSql;
                oTemplatePageInfo.IsPagerOpered = true;
                isPager = true;
            }

            if (oDictionary.ContainsKey("nodeid"))
            {
                oTableReturn = m_IDAL.GetListByNodeids(oDictionary["nodeid"], strNum, strOrderby, strWhere, strIgnore, false, strReturnkey, oDictionary.ContainsKey("allsubnode"));
            }
            if (oDictionary.ContainsKey("tableid"))
            {
                oTableReturn = m_IDAL.GetListByTableId(oDictionary["tableid"], strNum, strOrderby, strWhere, strIgnore, false, strReturnkey);
            }
            if (oDictionary.ContainsKey("nodeguid"))
            {
                oTableReturn = m_IDAL.GetListByNodeGuid(oDictionary["nodeguid"], strNum, strOrderby, strWhere, strIgnore, false, strReturnkey);
            }

            if (oTableReturn == null)
                oTableReturn = new DataTable();

            if (isPager && oTableReturn.Rows.Count <= 0)
            {
                oTemplatePageInfo.IsCurrentPageDataError = true;
            }

            return oTableReturn;

            #endregion
        }

        #region 分页辅助

        //Rec 获取总数
        public static void RecPagePutRealCount(Dictionary<string, string> oDicDataTableParam, string strWhere, TemplateDllPageInfo m_PageInfo)
        {
            if (m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.RecPage &&
                m_PageInfo.IsFindPager &&
                m_PageInfo.IsPagerOpered == false)
            {
                m_PageInfo.intPageRealCount = m_IDAL.GetCommentCount(oDicDataTableParam["indexid"]);
            }
        }

        //Search 获取总数
        public static void ListPagePutRealCountForSearch(Dictionary<string, string> oDicDataTableParam, string strField, string strKeywords, string strSeparator, string strIgnorecontentid, string strWhere, bool blnExact, TemplateDllPageInfo m_PageInfo)
        {
            if (m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.IndexPage &&
                m_PageInfo.IsFindPager &&
                m_PageInfo.IsPagerOpered == false)
            {
                if (oDicDataTableParam.ContainsKey("nodeid"))
                {
                    if (oDicDataTableParam.ContainsKey("allsubnode") && oDicDataTableParam["allsubnode"] == "true")
                    {
                        m_PageInfo.intPageRealCount = m_IDAL.GetSearchWithAllSonByNodeid(oDicDataTableParam["nodeid"], strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, blnExact, false);
                    }
                    else
                    {
                        m_PageInfo.intPageRealCount = m_IDAL.GetSearchByNodeid(oDicDataTableParam["nodeid"], strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, blnExact, false);
                    }
                }
                else if (oDicDataTableParam.ContainsKey("tableid"))
                {
                    m_PageInfo.intPageRealCount = m_IDAL.GetSearchByTableid(oDicDataTableParam["tableid"], strField, strKeywords, strSeparator, strIgnorecontentid, strWhere, blnExact, false);
                }
            }
        }

        //list 获取总数
        private static void ListPagePutRealCount(Dictionary<string, string> oDicDataTableParam, string strWhere, string strIgnore, TemplateDllPageInfo m_PageInfo)
        {
            if (m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.IndexPage &&
                m_PageInfo.IsFindPager &&
                m_PageInfo.IsPagerOpered == false)
            {
                if (oDicDataTableParam.ContainsKey("nodeid"))
                {
                    m_PageInfo.intPageRealCount = m_IDAL.GetListByNodeids(oDicDataTableParam["nodeid"], strWhere, strIgnore, false, oDicDataTableParam.ContainsKey("allsubnode"));
                }
                if (oDicDataTableParam.ContainsKey("tableid"))
                {
                    m_PageInfo.intPageRealCount = m_IDAL.GetListByTableId(oDicDataTableParam["tableid"], strWhere, strIgnore, false);
                }
                if (oDicDataTableParam.ContainsKey("nodeguid"))
                {
                    m_PageInfo.intPageRealCount = m_IDAL.GetListByNodeGuid(oDicDataTableParam["nodeguid"], strWhere, strIgnore, false);
                }
            }
        }

        //SQL 获取总数
        public static void ListPagePutRealCountForSQL(string strQuery, bool blnCache, string strReturnkey, TemplateDllPageInfo m_PageInfo)
        {
            if (m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.IndexPage &&
                m_PageInfo.IsFindPager &&
                m_PageInfo.IsPagerOpered == false)
            {
                m_PageInfo.intPageRealCount = m_IDAL.GetCountbySQLQuery(strQuery, blnCache, strReturnkey);
            }
        }

        /// <summary>
        /// 如果分页，则记录分页信息
        /// </summary>
        /// <param name="oDicDataTableParam"></param>
        /// <param name="m_PageInfo"></param>
        private static void CheckifPage(Dictionary<string, string> oDicDataTableParam, TemplateDllPageInfo m_PageInfo)
        {
            if (CheckTemplateTypeForList(m_PageInfo) &&
                oDicDataTableParam["num"].Contains("page") &&
                m_PageInfo.IsFindPager == false
                )//分页的情况下
            {
                m_PageInfo.IsFindPager = true;
                m_PageInfo.intPageSize = oDicDataTableParam["num"].Replace("page-", "").ToInt();
                oDicDataTableParam["num"] = "0";
                //if (m_PageInfo.intListPagePubCount > 0 && m_PageInfo.intListPagePubIndex > 0)
                if (m_PageInfo.intListPagePubIndex > 0)
                {
                    m_PageInfo.strPageWhereSql = "      IndexFlag > " + ((m_PageInfo.intListPagePubIndex - 1) * m_PageInfo.intPageSize).ToString() + " and  IndexFlag <= " + ((m_PageInfo.intListPagePubIndex) * m_PageInfo.intPageSize).ToString();
                }
            }
            else
            {
                oDicDataTableParam["num"] = oDicDataTableParam["num"].Replace("page-", "");
            }

        }
        /// <summary>
        /// 检验是否可分页
        /// </summary>
        /// <param name="m_PageInfo"></param>
        /// <returns></returns>
        private static bool CheckTemplateTypeForList(TemplateDllPageInfo m_PageInfo)
        {
            return (
                m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.IndexPage ||
                m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.RecPage ||
                m_PageInfo.enumTemplateType == TRPOP.CMS.Plugin.EnumList.TemplateType.SearchPage
                );
        }
        #endregion

    }
}